package ui 
{
	import flash.display.DisplayObject;
	import flash.display.Stage;
	/**
	 * ...
	 * @author Surui
	 */
	public class GameCamera 
	{
		private var m_stage:Stage;
		private var m_target:UIMap;
		private static var m_self:GameCamera;
		public function GameCamera() 
		{
		}
		public static function get self():GameCamera {
			m_self = m_self ? m_self : new GameCamera();
			return m_self;
		}
		
		public function update():void {
			if ( m_target.xx > 0 ) {
				m_target.x = m_target.xx = 0;
			} else if( m_target.xx + m_target.width < m_stage.stageWidth ) {
				m_target.x = m_target.xx = m_stage.stageWidth - m_target.width;
			} else {
				m_target.x = m_target.xx;
			}
			if ( m_target.yy > 0 ) {
				m_target.y = m_target.yy = 0;
			} else if( m_target.yy + m_target.height < m_stage.stageHeight ) {
				m_target.y = m_target.yy = m_stage.stageHeight - m_target.height;
			} else {
				m_target.y = m_target.yy;
			}
		}
		
		public function follow( target:UIMap ):void {
			m_target = target;
		}
		
		public function setStage( stage:Stage ):void {
			m_stage = stage;
		}
		
		public function resetCamera():void {
			m_target.x = 0;
			m_target.y = 0;
		}
	}

}